home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 15018 / 15018.xpi / chrome / TChanger.jar / content / TChanger / TChangerOverlay.js < prev    next >
Encoding:
Text File  |  2009-11-26  |  15.2 KB  |  361 lines

  1.  
  2. //Tab Throbber Changer, must pass a 16x16 pixel image
  3.  
  4. if(!com) var com = {};
  5. if(!com.TChanger) com.TChanger = {};
  6. if(!com.TChanger.TChangerP) com.TChanger.TChangerP = {};
  7.  
  8. com.TChanger.TChangerP = {
  9.  
  10.   ThrobberT: function() {
  11.     const nsIFilePicker = Components.interfaces.nsIFilePicker;
  12.   
  13.     var fp = Components.classes["@mozilla.org/filepicker;1"]
  14.                .createInstance(nsIFilePicker);
  15.       fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
  16.       fp.appendFilters(nsIFilePicker.filterImages);
  17.  
  18.  
  19.     var rv = fp.show();
  20.       if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
  21.           var file = fp.file;
  22.     // Get the path as string
  23.           var path = fp.file.path;
  24.     // work with returned nsILocalFile...
  25.         
  26.     //Get Chrome Directory
  27.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  28.                      getService(Components.interfaces.nsIProperties).
  29.                      get("UChrm", Components.interfaces.nsIFile);
  30.       
  31.     var copythis = Components.classes["@mozilla.org/file/directory_service;1"].
  32.                      getService(Components.interfaces.nsIProperties).
  33.                      get("UChrm", Components.interfaces.nsIFile);
  34.                      
  35.           // Point "directory" to the file that we want to test for existance
  36.           // store true or false in variable "c"
  37.           directory.append("run16.gif");           
  38.           var c = directory.exists()
  39.   
  40.            // Condition, if the file "run16.gif" exists then delete it and copy the new one
  41.            // else copy the new one to the chrome directory
  42.           if (c==true){
  43.           directory.remove(false);
  44.           file.copyTo(copythis,"run16.gif");}
  45.           else
  46.           file.copyTo(copythis,"run16.gif");
  47.         
  48.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  49.                      getService(Components.interfaces.nsIProperties).
  50.                      get("UChrm", Components.interfaces.nsIFile);
  51.                      
  52.         directory.append("run20.gif");           
  53.         var a = directory.exists()            
  54.                            
  55.   var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  56.                       getService(Components.interfaces.nsIProperties).
  57.                       get("UChrm", Components.interfaces.nsIFile);
  58.                      
  59.           directory.append("static20.png");           
  60.           var b = directory.exists() 
  61.         
  62.           //Make sure that we only write to UserChrome.css once
  63.           var z = 0;
  64.               
  65.           if (c == false && b == false && a == false){
  66.             com.TChanger.TChangerP.writetofile();
  67.           } else
  68.           if (c == false && b == true && a == true){
  69.             z = 1;
  70.           } else
  71.           if (c == false && b == true && a == false){
  72.             z = 2;
  73.           } else
  74.           if (c == false && b == false && a == true){
  75.             z = 3;
  76.           } 
  77.       }
  78.   },
  79.  
  80.   
  81.   ThrobberA: function() {
  82.  
  83.   const nsIFilePicker = Components.interfaces.nsIFilePicker;
  84.  
  85.     var fp = Components.classes["@mozilla.org/filepicker;1"]
  86.                .createInstance(nsIFilePicker);
  87.       fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
  88.       fp.appendFilters(nsIFilePicker.filterImages);
  89.  
  90.  
  91.     var rv = fp.show();
  92.        if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
  93.           var file = fp.file;
  94.     // Get the path as string
  95.           var path = fp.file.path;
  96.     // work with returned nsILocalFile...
  97.            
  98.     //Get Chrome Directory
  99.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  100.                        getService(Components.interfaces.nsIProperties).
  101.                        get("UChrm", Components.interfaces.nsIFile);
  102.  
  103.     var copythis = Components.classes["@mozilla.org/file/directory_service;1"].
  104.                        getService(Components.interfaces.nsIProperties).
  105.                        get("UChrm", Components.interfaces.nsIFile);
  106.                        
  107.           // Point "directory" to the file that we want to test for existance
  108.           // store true or false in variable "a"
  109.           directory.append("run20.gif");           
  110.           var a = directory.exists()
  111.     
  112.           // Condition, if the file "run20.gif" exists then delete it and copy the new one
  113.           // else copy the new one to the chrome directory
  114.           if (a==true){
  115.           directory.remove(false);
  116.           file.copyTo(copythis,"run20.gif");}
  117.           else
  118.           file.copyTo(copythis,"run20.gif");
  119.     
  120.           var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  121.                        getService(Components.interfaces.nsIProperties).
  122.                        get("UChrm", Components.interfaces.nsIFile);
  123.                        
  124.           directory.append("run16.gif");           
  125.           var c = directory.exists()            
  126.                              
  127.           var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  128.                        getService(Components.interfaces.nsIProperties).
  129.                        get("UChrm", Components.interfaces.nsIFile);
  130.                        
  131.           directory.append("static20.png");           
  132.           var b = directory.exists() 
  133.           
  134.           //Make sure that we only write to UserChrome.css once      
  135.           var z = 0;
  136.                 
  137.           if (b == false && c == false && a == false){
  138.             com.TChanger.TChangerP.writetofile();
  139.           } else
  140.           if (b == false && c == true && a == true){
  141.             z = 1;
  142.           } else
  143.           if (b == false && c == true && a == false){
  144.             z = 2;
  145.           } else
  146.           if (b == false && c == false && a == true){
  147.             z = 3;
  148.           } 
  149.          
  150.         } 
  151.          
  152.     },
  153.  
  154.   ThrobberS: function() {
  155.  
  156.   const nsIFilePicker = Components.interfaces.nsIFilePicker;
  157.  
  158.     var fp = Components.classes["@mozilla.org/filepicker;1"]
  159.                .createInstance(nsIFilePicker);
  160.       fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
  161.       fp.appendFilters(nsIFilePicker.filterImages);
  162.  
  163.  
  164.     var rv = fp.show();
  165.        if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
  166.           var file = fp.file;
  167.     // Get the path as string
  168.           var path = fp.file.path;
  169.     // work with returned nsILocalFile...
  170.           
  171.     //Get Chrome Directory
  172.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  173.                        getService(Components.interfaces.nsIProperties).
  174.                        get("UChrm", Components.interfaces.nsIFile);
  175.  
  176.     var copythis = Components.classes["@mozilla.org/file/directory_service;1"].
  177.                        getService(Components.interfaces.nsIProperties).
  178.                        get("UChrm", Components.interfaces.nsIFile);
  179.                        
  180.           // Point "directory" to the file that we want to test for existance
  181.           // store true or false in variable "b"
  182.           directory.append("static20.png");           
  183.           var b = directory.exists()
  184.     
  185.           // Condition, if the file "static20.png" exists then delete it and copy the new one
  186.           // else copy the new one to the chrome directory
  187.           if (b==true){
  188.           directory.remove(false);
  189.           file.copyTo(copythis,"static20.png");}
  190.           else
  191.           file.copyTo(copythis,"static20.png");    
  192.           
  193.           var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  194.                        getService(Components.interfaces.nsIProperties).
  195.                        get("UChrm", Components.interfaces.nsIFile);
  196.                        
  197.           directory.append("run16.gif");           
  198.           var c = directory.exists()            
  199.                              
  200.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  201.                        getService(Components.interfaces.nsIProperties).
  202.                        get("UChrm", Components.interfaces.nsIFile);
  203.                        
  204.           directory.append("run20.gif");           
  205.           var a = directory.exists() 
  206.           
  207.           //Make sure that we only write to UserChrome.css once     
  208.           var z = 0;
  209.                 
  210.           if (a == false && c == false && b == false){
  211.             com.TChanger.TChangerP.writetofile();
  212.           } else
  213.           if (a == false && c == true && b == true){
  214.             z = 1;
  215.           } else
  216.           if (a == false && c == true && b == false){
  217.             z = 2;
  218.           } else
  219.           if (a == false && c == false && b == true){
  220.             z = 3;
  221.           } 
  222.           
  223.       }
  224.   },
  225.  
  226.   restartFF: function() {
  227.     const Cc = Components.classes;
  228.     const Ci = Components.interfaces;
  229.     const Cr = Components.results;
  230.        
  231.   var as = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
  232.   as.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eForceQuit);
  233.    
  234.   },
  235.  
  236.  
  237.   writetofile: function() {
  238.  
  239.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  240.                        getService(Components.interfaces.nsIProperties).
  241.                        get("UChrm", Components.interfaces.nsIFile);
  242.         
  243.     var copythis = Components.classes["@mozilla.org/file/directory_service;1"].
  244.                        getService(Components.interfaces.nsIProperties).
  245.                        get("UChrm", Components.interfaces.nsIFile);
  246.                        
  247.           // Point "directory" to the file that we want to test for existance
  248.           // store true or false in variable "c"
  249.           directory.append("userchrome.css");           
  250.           var c = directory.exists()
  251.     
  252.           // Condition, if the file "userchrome.css" exists then copy it a
  253.           // save it as "userchrome.css.bak"
  254.           if (c==true){
  255.           directory.copyTo(copythis,"userchrome.css.bak");}
  256.                      
  257.     var writefile = Components.classes["@mozilla.org/file/directory_service;1"].
  258.                        getService(Components.interfaces.nsIProperties).
  259.                        get("UChrm", Components.interfaces.nsIFile);
  260.      //Point the file to write to as UserChrome.css
  261.      
  262.           writefile.append("userChrome.css");
  263.           file = writefile;
  264.           
  265.       // file is nsIFile, data is a string
  266.     var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
  267.                              createInstance(Components.interfaces.nsIFileOutputStream);
  268.  
  269.     // use 0x02 | 0x10 to open file for appending.
  270.     foStream.init(file, 0x02 | 0x08 | 0x10, 0666, 0); 
  271.     // write, create, truncate
  272.     // In a c file operation, we have no need to set file mode with or operation,
  273.     // directly using "r" or "w" usually.
  274.  
  275.     // if you are sure there will never ever be any non-ascii text in data you can 
  276.     // also call foStream.writeData directly
  277.     var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
  278.                               createInstance(Components.interfaces.nsIConverterOutputStream);
  279.     converter.init(foStream, "UTF-8", 0, 0);
  280.     converter.writeString("\n toolbar[iconsize=small] #navigator-throbber[busy=true] {list-style-image: url(run20.gif) !important; opacity: 1 !important} \n toolbar[iconsize=small] #navigator-throbber[busy=true] {list-style-image: url(run20.gif) !important; opacity: 1 !important} \n toolbar[iconsize=small] #navigator-throbber { list-style-image: url(static20.png) !important; } \n toolbar[iconsize=large] #navigator-throbber { list-style-image: url(static20.png) !important; } \n toolbar[iconsize=large] #navigator-throbber[busy=true] { list-style-image: url(run20.gif) !important; opacity: 1 !important} \n #content tab[busy] .tab-icon-image {list-style-image: url(run16.gif) !important; opacity: 1 !important} \n #content tab[busy] .tab-icon {list-style-image: url(run16.gif) !important; opacity: 0.6 !important}");
  281.     converter.close(); // this closes foStream
  282.  
  283.   },
  284.  
  285.   deleteall: function() {
  286.  
  287.     var tab = Components.classes["@mozilla.org/file/directory_service;1"].
  288.                        getService(Components.interfaces.nsIProperties).
  289.                        get("UChrm", Components.interfaces.nsIFile);
  290.                        
  291.     var toolone = Components.classes["@mozilla.org/file/directory_service;1"].
  292.                        getService(Components.interfaces.nsIProperties).
  293.                        get("UChrm", Components.interfaces.nsIFile);
  294.                        
  295.     var tooltwo = Components.classes["@mozilla.org/file/directory_service;1"].
  296.                        getService(Components.interfaces.nsIProperties).
  297.                        
  298.                        get("UChrm", Components.interfaces.nsIFile);
  299.                        
  300.     var userchrm = Components.classes["@mozilla.org/file/directory_service;1"].
  301.                        getService(Components.interfaces.nsIProperties).
  302.                        get("UChrm", Components.interfaces.nsIFile);
  303.                        
  304.     var renamer = Components.classes["@mozilla.org/file/directory_service;1"].
  305.                        getService(Components.interfaces.nsIProperties).
  306.                        get("UChrm", Components.interfaces.nsIFile);
  307.     
  308.     var directory = Components.classes["@mozilla.org/file/directory_service;1"].
  309.                        getService(Components.interfaces.nsIProperties).
  310.                        get("UChrm", Components.interfaces.nsIFile);
  311.         
  312.     var copythis = Components.classes["@mozilla.org/file/directory_service;1"].
  313.                        getService(Components.interfaces.nsIProperties).
  314.                        get("UChrm", Components.interfaces.nsIFile);
  315.                        
  316.           // Point "directory" to the file that we want to test for existance
  317.           // store true or false in variable "c"
  318.           directory.append("userchrome.css");           
  319.           userchrm.append("userchrome.css");
  320.           renamer.append("userchrome.css.bak");
  321.           var d = userchrm.exists();
  322.           var e = renamer.exists();
  323.           var m = directory.exists()
  324.     
  325.           // Condition, if the file "userchrome.css" exists then copy it a
  326.           // save it as "userchrome.css.bak"
  327.           if (m == true && renamer == false){
  328.           directory.copyTo(copythis,"userchrome.css.bak");}
  329.           
  330.                                      
  331.     tab.append("run16.gif");
  332.     var c = tab.exists()
  333.     if (c==true){
  334.           tab.remove(false);}
  335.           
  336.     
  337.     toolone.append("run20.gif");
  338.     var a = toolone.exists()
  339.     if (a==true){
  340.           toolone.remove(false);}
  341.     
  342.     tooltwo.append("static20.png");
  343.     var b = tooltwo.exists()
  344.     if (b==true){
  345.           tooltwo.remove(false);}
  346.    
  347.     if (d == true && e == true){
  348.           userchrm.remove(false);
  349.           renamer.copyTo(null,"userchrome.css");
  350.           renamer.remove(false);}
  351.     //if (d == true && e == ){
  352.     //       userchrm.remove(false);}
  353.             
  354.   },   
  355.   
  356.  
  357.   TOptions: function() {
  358.   window.openDialog("chrome://TChanger/content/options.xul", "_blank","chrome,modal,centerscreen,resizable=no");
  359.   }
  360. }
  361.